<?php 
class CenterController extends CommonController{

	// 主页
	public function index(){
		// 获得uid
		$uid = Q('session.uid',0,'intval');
		// 获取用户信息
		$userData = K('User')->where("uid={$uid}")->find();
		// 分配给前端
		$this->assign('userData',$userData);
		
		// 获得w值
		$w = Q('get.w',0,'intval');
		switch ($w) {
			case 0:
				$data = M()->join("__f_order_list__ ol JOIN __f_order__ o ON ol.f_order_oid=o.oid JOIN __f_goods__ g ON ol.f_goods_gid=g.gid")->where("o.f_user_uid={$uid}")->all();
				break;
			case 1:
				$data = M()->join("__f_order_list__ ol JOIN __f_order__ o ON ol.f_order_oid=o.oid JOIN __f_goods__ g ON ol.f_goods_gid=g.gid")->where("o.f_user_uid={$uid}&&o.state='未付款'")->all();
				break;
			case 2:
				$data = M()->join("__f_order_list__ ol JOIN __f_order__ o ON ol.f_order_oid=o.oid JOIN __f_goods__ g ON ol.f_goods_gid=g.gid")->where("o.f_user_uid={$uid}&&o.state='待发货'||o.state='已发货'")->all();
				break;
			case 3:
				$data = M()->join("__f_order_list__ ol JOIN __f_order__ o ON ol.f_order_oid=o.oid JOIN __f_goods__ g ON ol.f_goods_gid=g.gid")->where("o.f_user_uid={$uid}&&o.state='已完成'")->all();
				break;
		}
		// 获得当前用户的订单
		// $data = M()->join("__f_order_list__ ol JOIN __f_order__ o ON ol.f_order_oid=o.oid JOIN __f_goods__ g ON ol.f_goods_gid=g.gid")->where("o.f_user_uid={$uid}&&o.state='待发货'")->all();
		
		foreach ($data as $k => $v) {
			$data[$k]['dan'] = $v['subtotal']/$v['buy_num'];
		}
		// p($data);
		// 分配给前端
		$this->assign('data',$data);
		// 显示模版
		$this->display();
	}

	// 确认收货
	// 发货
	public function collect(){
		// 获得订单id
		$oid = Q('get.oid',0,'intval');
		// 更改数据库
		$data = array('oid'=>$oid,'state'=>'已完成');
		K('Order')->update($data);
		$this->success('交易完成');
	}
}












 ?>